﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MicropleSoft.WmsApp.Library.ApplicationObserver
{
    public partial class DataSourceControlObserver : IDataSourceControlObserver
    {
        /// <summary>
        /// 每个kv中放入一个List
        /// </summary>
        private readonly static Hashtable HashtableInstance = new Hashtable();
        public void AddControl(System.Windows.Forms.Control control, string dataSourceKey)
        {
            var list = GetControlsByDataSourceKey(dataSourceKey);
            if(!list.Contains(control))
            {
                list.Add(control);
            }
        }

        public List<System.Windows.Forms.Control> GetControlsByDataSourceKey(string dataSourceKey)
        {
            var obj = HashtableInstance[dataSourceKey];
            if(obj != null)
                return (List<System.Windows.Forms.Control>) obj;
            HashtableInstance[dataSourceKey] = new List<System.Windows.Forms.Control>();
            return GetControlsByDataSourceKey(dataSourceKey);
        }

        public void RemoveControl(System.Windows.Forms.Control control, string dataSourceKey)
        {
            var list = GetControlsByDataSourceKey(dataSourceKey);
            list.Remove(control);
        }
    }
}
